using Microsoft.AspNetCore.Mvc;
using ZR.Model.TaskManage.Dto;
using ZR.Model.TaskManage;
using ZR.Service.TaskManage.ITaskManageService;
using ZR.Admin.WebApi.Filters;

//创建时间：2025-05-06
namespace ZR.Admin.WebApi.Controllers.TaskManage
{
    /// <summary>
    /// 拣选任务
    /// </summary>
    [Verify]
    [Route("TaskManage/TaskPick")]
    public class TaskPickController : BaseController
    {
        /// <summary>
        /// 拣选任务接口
        /// </summary>
        private readonly ITaskPickService _TaskPickService;

        public TaskPickController(ITaskPickService TaskPickService)
        {
            _TaskPickService = TaskPickService;
        }

        /// <summary>
        /// 查询拣选任务列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("pageList")]
        [ActionPermissionFilter(Permission = "task:pick:list")]
        public IActionResult PageTaskPick([FromQuery] TaskPickQueryDto parm)
        {
            var response = _TaskPickService.GetPageList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询拣选任务详情
        /// </summary>
        /// <param name="PickId"></param>
        /// <returns></returns>
        [HttpGet("{PickId}")]
        [ActionPermissionFilter(Permission = "task:pick:query")]
        public IActionResult GetTaskPick(string PickId)
        {
            var response = _TaskPickService.GetInfo(PickId);
            
            var info = response.Adapt<TaskPickDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加拣选任务
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "task:pick:add")]
        [Log(Title = "拣选任务", BusinessType = BusinessType.INSERT)]
        public IActionResult AddTaskPick([FromBody] TaskPickDto parm)
        {
            var modal = parm.Adapt<TaskPick>().ToCreate(HttpContext);

            var response = _TaskPickService.AddTaskPick(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新拣选任务
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "task:pick:edit")]
        [Log(Title = "拣选任务", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateTaskPick([FromBody] TaskPickDto parm)
        {
            var modal = parm.Adapt<TaskPick>().ToUpdate(HttpContext);
            var response = _TaskPickService.UpdateTaskPick(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除拣选任务
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete")]
        [ActionPermissionFilter(Permission = "task:pick:delete")]
        [Log(Title = "拣选任务", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteTaskPick([FromBody] string[] ids)
        {
            return ToResponse(_TaskPickService.Delete(ids));
        }

    }
}